﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;

namespace Voize
{
    internal class CPlayPosition
    {


        internal CPlayPosition(ref TrackBar PlayBar)
        {
            m_PlayBar = PlayBar;
        }



        private TrackBar m_PlayBar;
        private int m_MaxValue;
        private delegate void SetMaxValueCallback();

        internal void SetMax(int value)
        {
            m_MaxValue = value;
            if (m_PlayBar.InvokeRequired)
            {
                SetMaxValueCallback callback = new SetMaxValueCallback(SetMaxValue);
                m_PlayBar.Invoke(callback);
            }
            else
                m_PlayBar.Maximum = value;
        }

        private void SetMaxValue()
        {
            m_PlayBar.Maximum = m_MaxValue;
        }

        internal void Clear()
        {
            m_PlayBar.Value = 0;
            m_PlayBar.Refresh();
        }



        internal void SetValue(int value)
        {
            if (value < m_PlayBar.Maximum)
            {
                if (value > 0)
                {
                    m_PlayBar.Value = value;
                    m_PlayBar.Refresh();
                }
            }
            else
            {
                m_PlayBar.Value = 0;
                m_PlayBar.Refresh();
            }
            
        }


    }
}
